#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const ll N = 1e5 + 10, INF = 0x3f3f3f3f;

ll n, q;
ll block, t;
ll st[N], ed[N], pos[N];
ll a[N], sum[N], add[N];

void init(ll n)
{
    block = sqrt(n);
    t = (n + block - 1) / block;
    for (ll i = 1;i <= t;i++) {
        st[i] = (i - 1) * block + 1;
        ed[i] = i * block;
    }
    ed[t] = n;
    for (ll i = 1;i <= n;i++)
        pos[i] = (i - 1) / block + 1;
}

void change(ll l, ll r, ll d)
{
    ll p = pos[l], q = pos[r];
    if (p == q) {
        for (ll i = l;i <= r;i++) a[i] += d;
        sum[p] += d * (r - l + 1);
    } else {
        for (ll i = p + 1;i <= q - 1;i++) add[i] += d;
        for (ll i = l;i <= ed[p];i++) a[i] += d;
        sum[p] += d * (ed[p] - l + 1);
        for (ll i = st[q];i <= r;i++) a[i] += d;
        sum[q] += d * (r - st[q] + 1);
    }
}

ll ask(ll l, ll r)
{
    ll p = pos[l], q = pos[r];
    ll ans = 0;
    if (p == q) {
        for (ll i = l;i <= r;i++) ans += a[i];
        ans += add[p] * (r - l + 1);
    } else {
        for (ll i = p + 1;i <= q - 1;i++) ans += sum[i] + add[i] * (ed[i] - st[i] + 1);
        for (ll i = l;i <= ed[p];i++) ans += a[i];
        ans += add[p] * (ed[p] - l + 1);
        for (ll i = st[q];i <= r;i++) ans += a[i];
        ans += add[q] * (r - st[q] + 1);
    }
    return ans;
}

void solve()
{
    cin >> n >> q;
    init(n);
    for (ll i = 1;i <= n;i++) cin >> a[i];
    for (ll i = 1;i <= t;i++)
        for (ll j = st[i];j <= ed[i];j++)
            sum[i] += a[j];

    ll op, l, r, d;
    while (q--) {
        cin >> op;
        if (op == 1) {
            cin >> l >> r >> d;
            change(l, r, d);
        } else {
            cin >> l >> r;
            cout << ask(l, r) << '\n';
        }
    }
}

signed main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll T = 1;
    //cin>>T;
    for (ll i = 1;i <= T;i++) {
        solve();
    }
}